package com.surprise;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import weibo4j.Weibo;

public class WebController extends HttpServlet {
	
	private static final long serialVersionUID = 3374637322218494298L;

	@Override
	public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
		try {
			Weibo weibo = WeiboHolder.getWeibo();
			if (weibo != null) {
				weibo.updateStatus(req.getParameter("status"));
			} else {
				throw new RuntimeException("weibo is null.");
			}
			resp.sendRedirect("index.html");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doGet(req, resp);
	}
}
